package com.miaostars.apakey.checks;

import com.miaostars.apakey.Apakey;
import com.miaostars.apakey.utils.PlayerData;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;

public class CombatChecks {
    
    private final Apakey plugin;
    
    public CombatChecks(Apakey plugin) {
        this.plugin = plugin;
    }
    
    public boolean checkKillAura(Player player, PlayerData data) {
        if (!plugin.getConfigManager().getConfig().getBoolean("checks.killaura.enabled")) {
            return false;
        }
        
        if (player.hasPermission("apakey.bypass")) {
            return false;
        }
        
        int maxCPS = plugin.getConfigManager().getConfig().getInt("checks.killaura.max-cps");
        long currentTime = System.currentTimeMillis();
        
        // Remove old clicks (older than 1 second)
        data.getClicks().removeIf(clickTime -> currentTime - clickTime > 1000);
        
        // Check CPS
        if (data.getClicks().size() >= maxCPS) {
            data.incrementKillAuraViolations();
            
            if (data.getKillAuraViolations() > plugin.getConfigManager().getConfig().getInt("checks.killaura.max-violations")) {
                return true;
            }
        } else {
            data.decrementKillAuraViolations();
        }
        
        return false;
    }
    
    public boolean checkReach(Player player, PlayerData data, double distance) {
        if (!plugin.getConfigManager().getConfig().getBoolean("checks.reach.enabled")) {
            return false;
        }
        
        if (player.hasPermission("apakey.bypass")) {
            return false;
        }
        
        double maxDistance = plugin.getConfigManager().getConfig().getDouble("checks.reach.max-distance");
        
        if (distance > maxDistance) {
            data.incrementReachViolations();
            
            if (data.getReachViolations() > plugin.getConfigManager().getConfig().getInt("checks.reach.max-violations")) {
                return true;
            }
        } else {
            data.decrementReachViolations();
        }
        
        return false;
    }
}